#include <iostream>
#include <cstring>
using namespace std;

const int N = 205;
int g[N][N], n, m, k;

void floyd()
{
    for(int k = 1; k <= n; ++k)
        for(int i = 1; i <= n; ++i)
            for(int j = 1; j <= n; ++j)
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
}

int main()
{
    memset(g, 0x3f, sizeof(g));
    cin >> n >> m >> k;
    for(int i = 0; i <= n; ++i) g[i][i] = 0;

    while(m--)
    {
        int a, b, c; cin >> a >> b >> c;
        g[a][b] = min(g[a][b], c);
    }
    
    floyd();
    
    while(k--)
    {
        int a, b; cin >> a >> b;
        if(g[a][b] > 0x3f3f3f3f/2) cout << "impossible" << endl;
        else cout << g[a][b] << endl;
    }

    return 0;
}